package cn.zyl.demo.web;

import cn.zyl.demo.api.DemoApiService;
import cn.zyl.demo.api.model.DemoApiModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 类说明:
 *
 * @author wsz
 * @version v1.0
 * @date 2020-07-15
 */
@Component
@RestController
@RequestMapping("/demo")
public class DemoController {
    @Autowired
    private DemoApiService userService;

    @RequestMapping("")
    public String index() {
        return "zyl.demo hello!";
    }

    @RequestMapping("/username")
    public String getUserName(@RequestParam("id") Long id) {
        return userService.getApiName(id);
    }

    @RequestMapping("/add")
    @ResponseBody
    public DemoApiModel addUser(@RequestParam("name") String name, @RequestParam("age") Integer age) {
        DemoApiModel user = new DemoApiModel();
        user.setName(name);
        user.setAge(age);
        return userService.queryDemoApiModel(user);
    }
}
